package designpatterns.creation;

/**
 * 普通工厂设计模式
 * 将对象的创建和使用分离
 *
 * @author jack.wu
 * @since 2019/9/18
 */
public class FactoryTest {

    public static void main(String[] args) {
        Car car = CarFactory.createCar("白色", 1999999D, "BMW");
        car.show();
    }
}

interface Car {
    /**
     * 查看
     */
    void show();
}

class Audi implements Car {
    private String color;
    private Double price;

    public Audi(String color, Double price) {
        this.color = color;
        this.price = price;
    }

    @Override
    public void show() {
        System.out.println(color + "颜色的奥迪,价格：" + price);
    }
}

class BMW implements Car {
    private String color;
    private Double price;

    public BMW(String color, Double price) {
        this.color = color;
        this.price = price;
    }

    @Override
    public void show() {
        System.out.println(color + "颜色的宝马,价格：" + price);
    }
}

class CarFactory {

    public static Car createCar(String color, Double price, String brand) {
        if ("audi".equals(brand)) {
            return new Audi(color, price);
        } else if ("BMW".equals(brand)) {
            return new BMW(color, price);
        }
        return null;
    }
}
